# coding:utf-8

from marshmallow import fields, validate

from app.op.constant import DemandCate
from ..extensions import ma
from .utils import EmptyStrValidator


class DemandImgSchema(ma.Schema):
    """
    created by chenhj at 2017/8/21

    """
    demand_id = fields.Int(required=True, error_messages={
        'required': '项目id不合法'
    })
    img = fields.Str(required=True, error_messages={
        'required': '图片不合法'
    }, validate=EmptyStrValidator(error='图片不合法'))

demand_img_schema = DemandImgSchema()


class DraftDemandEditSchema(ma.Schema):
    """
    created by chenhj at 2017/10/17

    """
    demand_id = fields.Int(required=True, error_messages={
        'required': '项目id不合法'
    })
    nickname = fields.Str()
    addr = fields.Str()
    prov = fields.Str(required=True, error_messages={
        'required': '省份不合法'
    }, validate=EmptyStrValidator(error='省份不合法'))
    city = fields.Str(required=True, error_messages={
        'required': '城市不合法'
    }, validate=EmptyStrValidator(error='城市不合法'))

draft_demand_edit_schema = DraftDemandEditSchema()


class ClientConsultSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13

    """
    supplier_id = fields.Int(required=True, error_messages={
        'required': '工程商id不合法'
    })

client_consult_schema = ClientConsultSchema()


class CertifySupCntSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13

    """
    city_id = fields.Int(required=True, error_messages={
        'required': '城市不合法'
    })

certify_sup_cnt_schema = CertifySupCntSchema()


class SupplierInfoInSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13

    """
    city_id = fields.Int(required=True, error_messages={
        'required': '城市id不合法'
    })
    supplier_id = fields.Int(required=True, error_messages={
        'required': '工程商id不合法'
    })

supplier_info_in_schema = SupplierInfoInSchema()


class SupplierParticListInSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13

    """
    partic_id = fields.Int(required=True, error_messages={
        'required': '参与id不合法'
    })
    supplier_id = fields.Int(required=True, error_messages={
        'required': '工程商id不合法'
    })

supplier_partic_list_in_schema = SupplierParticListInSchema()


class SupplierInfoOutSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13
    工程商详情
    """
    id = fields.Int()
    avatar = fields.Str(attribute='avatar_url')
    nickname = fields.Str()
    com = fields.Str()
    info_bid_count = fields.Int()
    info_consult_count = fields.Int()
    info_com_summary = fields.Str()
    has_install = fields.Bool()
    has_repair = fields.Bool()
    has_rent = fields.Bool()

supplier_info_out_schema = SupplierInfoOutSchema()


class FinishImgListSchema(ma.Schema):
    """
    created by chenhj at 2017/11/14

    """
    city = fields.Str()
    cate = fields.Str()
    surr = fields.Str()
    size = fields.Str()
    color = fields.Str()
    span = fields.Str()
    addr = fields.Str()
    created_at = fields.Int()
    img = fields.Str()
    type = fields.Int()

finish_img_list_schema = FinishImgListSchema(many=True)


class ParticInfoListSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13

    """
    partic_id = fields.Int()
    nickname = fields.Str()
    city = fields.Str()
    cate = fields.Str()
    surr = fields.Str()
    size = fields.Str()
    color = fields.Str()
    span = fields.Str()
    addr = fields.Str()
    published_at = fields.Int()
    type = fields.Int()

partic_info_list_schema = ParticInfoListSchema(many=True)


class SupplierListInSchema(ma.Schema):
    """
    created by chenhj at 2017/11/14

    """
    cate = fields.Int(required=True, error_messages={
        'required': '需求分类不合法'
    }, validate=validate.OneOf(DemandCate.values(), error='需求分类不合法'))
    city_id = fields.Int(required=True, error_messages={
        'required': '城市id不合法'
    })
    current_page = fields.Int(required=True, error_messages={
        'required': '页数不合法'
    }, validate=validate.Range(min=1, error='页数不合法'))

supplier_list_in_schema = SupplierListInSchema()


class SupplierListOutSchema(ma.Schema):
    """
    created by chenhj at 2017/11/13
    工程商列表
    """
    id = fields.Int()
    avatar = fields.Str(attribute='avatar_url')
    nickname = fields.Str()
    com = fields.Str()
    info_bid_count = fields.Int()
    has_install = fields.Bool()
    has_repair = fields.Bool()
    has_rent = fields.Bool()

supplier_list_out_schema = SupplierListOutSchema(many=True)
